package star.cloud.asme.system.user;

import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import star.cloud.asme.base.dto.Result;
import star.cloud.asme.base.mybatis.IBaseController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@Slf4j
@RequestMapping("/system/user")
public class UserController implements IBaseController<User> {

    private final UserService userService;

    @Override
    public Result<User> getOneByCondition(String conditionParamName, Object conditionParamValue) {
        return userService.getOneByCondition(conditionParamName, conditionParamValue);
    }

    @Override
    public Result<List<User>> getListByCondition(String conditionParamName, Object conditionParamValue) {
        return userService.getListByCondition(conditionParamName, conditionParamValue);
    }

    @Override
    public Result<List<User>> getListByConditions(User conditions) {
        return userService.getListByConditions(conditions);
    }

    @Override
    public Result<IPage<User>> getListByConditionsWithPage(User conditions) {
        return userService.getListByConditionsWithPage(conditions);
    }

    @Override
    @PreAuthorize("hasAuthority('管理员')")
    public Result<?> physicalDeleteById(Long id) {
        return userService.physicalDeleteById(id);
    }

    @Override
    @PreAuthorize("hasAuthority('逻辑删除用户')")
    public Result<?> logicalDeleteById(Long id) {
        return userService.logicalDeleteById(id);
    }

    @Override
    public Result<?> activeById(Long id) {
        return userService.activeById(id);
    }

    @Override
    public Result<User> insertOne(User entity) {
        return userService.insertOne(entity);
    }

    @Override
    @PreAuthorize("hasAuthority('修改用户')")
    public Result<User> updateOne(User entity) {
        return userService.updateOne(entity);
    }

    @Override
    public void exportToExcel(HttpServletResponse response) {
        userService.exportToExcel(response);
    }

    @Override
    public void importFromExcel(Long creator, MultipartFile file) {
        userService.importFromExcel(creator, file);
    }

    @GetMapping("/listUserIdAndUsername")
    public Result<List<User>> listUserIdAndUsername() {
        return userService.myListUserIdAndUsername();
    }

}
